﻿using System;
using System.Collections.Generic;
using Alex.Library.Specifications;

namespace Alex.Framework.Domain.Repositories
{
    /// <summary>
    /// 仓储基类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class Repository<T> : IRepository<T> where T : IAggregateRoot
    {
        #region Privates

        private readonly IRepositoryContext context;

        #endregion

        #region Ctor

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="context"></param>
        public Repository(IRepositoryContext context)
        {
            this.context = context;
        }

        #endregion

        #region Publics

        /// <summary>
        /// 仓储所属的上下文
        /// </summary>
        public IRepositoryContext Context
        {
            get { return this.context; }
        }

        /// <summary>
        /// 根据聚合根唯一标识获取对象，未实现，子类需覆盖该方法
        /// </summary>
        /// <param name="rootId">聚合根唯一标识</param>
        /// <returns>聚合根实体</returns>
        public virtual T GetByRootID(string rootId)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 根据条件查询聚合根实体集合
        /// </summary>
        /// <param name="specification">查询条件</param>
        /// <returns>聚合根实体集合</returns>
        public abstract IEnumerable<T> FindAll(ISpecification<T> specification);

        /// <summary>
        /// 根据条件查询聚合根实体
        /// </summary>
        /// <param name="specification">查询条件</param>
        /// <returns>聚合根实体</returns>
        public abstract T Find(ISpecification<T> specification);

        /// <summary>
        /// 判断聚合根实体是否存在与仓储中，未实现，子类需覆盖该方法
        /// </summary>
        /// <param name="specification">查询条件</param>
        /// <returns></returns>
        public virtual bool Exists(ISpecification<T> specification)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 向仓储中添加聚合根实体，未实现，子类需覆盖该方法
        /// </summary>
        /// <param name="root">聚合根实体</param>
        public virtual void Add(T root)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 修改仓储中的聚合根实体信息，未实现，子类需覆盖该方法
        /// </summary>
        /// <param name="root">新的聚合根实体</param>
        public virtual void Update(T root)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 删除仓储中的聚合根实体，未实现，子类需覆盖该方法
        /// </summary>
        /// <param name="root">待删除的聚合根实体</param>
        public virtual void Remove(T root)
        {
            throw new NotImplementedException();
        }

        #endregion        
    }
}
